package com.kgc.scd.controller;

import com.kgc.scd.annotation.RequestShopUser;
import com.kgc.scd.annotation.TokenPermission;
import com.kgc.scd.bean.ShopUser;
import com.kgc.scd.service.WebCategoriesInfoService;
import com.kgc.scd.service.WebGoodsCommentService;
import com.kgc.scd.util.RequestResult;
import com.kgc.scd.util.ResultBuildUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.coyote.OutputBuffer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

/**
 * Created On : 2022/11/16.
 * <p>
 * Author : 22166
 * <p>
 * Description: WebCategoriesInfoController
 */
@RestController
@Slf4j
@Api(tags = "操作入口")
public class WebCategoriesInfoController {

    @Resource
    private WebCategoriesInfoService  webCategoriesInfoService;


    @Resource
    private WebGoodsCommentService webGoodsCommentService;

    /**
     * @author : 22166
     * @date   : 2022/11/17
     * @param  : [sumCategory]
     * @return : com.kgc.scd.util.RequestResult<?>
     * @description : shopCategoriesList
     */
    @GetMapping("/shopCategoriesList")
    @TokenPermission
    @ApiOperation(value = "查询商品总分类")
    public RequestResult<?> shopCategoriesList(@RequestParam(required = false) Integer sumCategory,
                                               @RequestParam(required = false) String categoryId,
                                               @ApiIgnore @RequestShopUser ShopUser shopUser){


        log.info("22222{}",shopUser.getId());


        if (sumCategory !=null && categoryId==""){
            return ResultBuildUtil.success(webCategoriesInfoService.categoryList(sumCategory));
        }else if (categoryId !="" ){
                return shopCategory(categoryId);
        }

        Map<String,Object> objectMap = new TreeMap<>();
        objectMap.put("a-shopCartTotal",webCategoriesInfoService.getShopCartTotal(shopUser.getId()));
        objectMap.put("b-categoryList",webCategoriesInfoService.categoriesList(sumCategory));
        objectMap.put("c-comment",webGoodsCommentService.queryAllWeb());
        return ResultBuildUtil.success(objectMap);
    }
    
    /**
     * @author : 22166
     * @date   : 2022/11/17
     * @param  : [categoryId]
     * @return : com.kgc.scd.util.RequestResult<?>
     * @description : shopCategory 
     */
    //@GetMapping("/shopCategory")
    public RequestResult<?> shopCategory(@RequestParam(required = false) String categoryId){


        return ResultBuildUtil.success(webCategoriesInfoService.shopGoodsVO(categoryId));
    }





}